package io.github.uicdb.et.attachment;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.tags.TagKey;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.world.item.Item;

public class EquippedTagHolder {
    public static final Codec<EquippedTagHolder> CODEC = RecordCodecBuilder.create(ins -> ins.group(
            TagKey.codec(BuiltInRegistries.ITEM.key()).listOf().fieldOf("tags").forGetter(o -> o.tags)
    ).apply(ins, EquippedTagHolder::new));

    final List<TagKey<Item>> tags;

    public EquippedTagHolder(List<TagKey<Item>> tags) {
        this.tags = new ArrayList<>(tags);
    }

    public EquippedTagHolder() {
        this.tags = new ArrayList<>();
    }

    public boolean has(TagKey<Item> tag) {
        return tags.contains(tag);
    }

    public void add(TagKey<Item> tag) {
        tags.add(tag);
    }

    public void remove(TagKey<Item> tag) {
        tags.remove(tag);
    }
}
